package com.imooc.common.thread.keep;

import cn.hutool.core.thread.ThreadUtil;

import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

public class WorkerTest {
    volatile static Worker worker = null;
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(5);
        AtomicReference<Integer> counter = new AtomicReference<>(new Integer(0));

        worker = new Worker();
        worker.setCounter(counter);
        Future<Map> future1 = service.submit(new WorkerTask(worker));//ThreadUtil.sleep(1);
//
        Future<Map> future2 = service.submit(new WorkerTask(worker));//ThreadUtil.sleep(1);
        Future<Map> future3 = service.submit(new WorkerTask(worker));//ThreadUtil.sleep(1);
        Future<Map> future4 = service.submit(new WorkerTask(worker));//ThreadUtil.sleep(1);
        Future<Map> future5 = service.submit(new WorkerTask(worker));//
        service.shutdown();

    }
}
